package com.zkj.response;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Servlet_Resp_Demo1 extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		/**
		 * 字节流
		 */
		// String msg = "呵呵呵呵呵呵~";// 默认是gb2312
		//
		// ServletOutputStream s = resp.getOutputStream();
		// byte[] b = msg.getBytes("utf-8");
		// s.write(b);
		/**
		 * 字符流
		 * 
		 * 字节流字符流在同一个servlet中互斥
		 */
		String data = "字符流输出中文到浏览器";
		resp.setCharacterEncoding("utf-8");// 更改字符流输出时使用的编码
		resp.setContentType("text/html;charset=UTF-8");
		PrintWriter out = resp.getWriter();
		out.write(data);

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

}
